package com.game.action;

import com.game.logic.core.ranking.RakingService;
import com.game.logic.ranking.GameRakingService;
import com.game.logic.ranking.WordRakingService;
import com.xs.action.annotate.ActionController;
import com.xs.action.annotate.ActionMethod;
import com.xs.build.server.websocket.channel.ClientManager;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/// 2-排行榜行为
@Slf4j
@RestController(value = "/rankingAction")
@ActionController(value = 2, name = "排行榜行为")
public class RankingAction {
    @Resource
    GameRakingService rakingService;
    @Resource
    private WordRakingService wordRakingService;

    /**
     * 1.查看局内贡献排行榜
     *
     * @param anchorInfoId 主播信息id
     */
    @GetMapping("/obtainContributionRanking")
    @ActionMethod(value = 1, name = "查看局内贡献排行榜")
    public void obtainContributionRanking(@NotNull Integer anchorInfoId) {
        ClientManager.sendMessageToClient(
                anchorInfoId.toString(),
                rakingService.obtainContributionRanking(anchorInfoId)
        );
    }

    /**
     * 2.查看局内战斗力排行榜
     *
     * @param anchorInfoId 主播信息id
     */
    @GetMapping("/combatEffectiveness")
    @ActionMethod(value = 2, name = "查看局内战斗力排行榜")
    public void combatEffectiveness(@NotNull Integer anchorInfoId) {
        ClientManager.sendMessageToClient(
                anchorInfoId.toString(),
                rakingService.combatEffectiveness(anchorInfoId)
        );
    }

    /**
     * 3.世界排行榜[根据排名查询]
     *
     * @param s 开始
     * @param t 结束
     * @return 世界排行榜
     */
    @GetMapping("/worldRanking")
    @ActionMethod(value = 3, name = "世界排行榜")
    public List<RakingService.RankInfo<WordRakingService.WorldFightingCapacityRakingInfo>> worldRanking(int s, int t) {
        return wordRakingService.list(s, t);
    }

    /**
     * 5.领取世界排行榜奖励
     *
     * @param userInfoId 用户信息id
     * @return 世界排行榜
     */
    @GetMapping("/obtainWorldRankingReward")
    @ActionMethod(value = 5, name = "领取世界排行榜奖励")
    public void obtainWorldRankingReward(@NotNull Integer userInfoId) {
        wordRakingService.obtainWorldRankingReward(userInfoId);
    }


    @GetMapping("/viewTheDesignatedPlayerSWorldRanking")
    @ActionMethod(value = 6, name = "查看指定玩家世界排行榜")
    public Long viewTheDesignatedPlayerSWorldRanking(@NotNull Integer userInfoId) {
        return wordRakingService.get(userInfoId);
    }
}
